<template>
	<view>
		<input placeholder="请输入新的昵称" placeholder-class="placeholder" @input="getValue" />
		<view class="submit" @tap="submit">提交</view>
	</view>
</template>

<script>
	import api from "@/common/api.js"
	export default {
		data() {
			return {
				value: "",
				userid: '',
			};
		},
		methods: {
			getValue(e) {
				this.value = e.detail.value
			},
			// 提交修改
			submit(e) {
				api.changeInfo({
					api: 'updatec',
					id: this.userid,
					name: this.value,
					table: 1
				}).then(res => {
					if (res.code === 200) {
						uni.showToast({
							icon: 'success',
							title: '修改成功',
							success: (res) => {
								setTimeout(() => {
									uni.navigateTo({
										url: '../myMessages/myMessages?id=' + this.userid
									})
								}, 500)
							}
						})
					} else {
						uni.showToast({
							title: '修改失败',
							icon: 'none',
							duration: 2000
						})
					}
				}).catch(err => {
					console.log(err)
				})
			}
		},
		onShareAppMessage(options) {
			let shareObj = {
				success: (res) => {
					if (res.errMsg == 'shareAppMessage:ok') {
						uni.showToast({
							title: '分享成功',
							icon: 'success',
							duration: 1500
						})
					}
				},
				fail: () => {
					if (res.errMsg == 'shareAppMessage:fail cancel') {
						uni.showToast({
							title: '取消分享',
							icon: 'none',
							duration: 2000
						})
					} else if (res.errMsg == 'shareAppMessage:fail') {
						// 转发失败，其中 detail message 为详细失败信息
					}
				},
				complete: () => {
					// 转发结束之后的回调（转发成不成功都会执行）
				}
			}
		},
		onLoad(options) {
			this.userid = options.id
		}
	}
</script>

<style lang="scss">
	input {
		width: 690rpx;
		height: 100rpx;
		line-height: 100rpx;
		margin: 30rpx auto 0;
		border-bottom: 1rpx solid #dfdfdf;
	}

	.submit {
		width: 690rpx;
		height: 90rpx;
		line-height: 90rpx;
		border-radius: 45rpx;
		text-align: center;
		background: #209FFC;
		color: #fff;
		font-size: 40rpx;
		font-family: PingFang SC;
		font-weight: 500;
		margin: 100rpx auto 0;
	}

	.placeholder {
		font-size: 30rpx;
		color: #999;
		padding-left: 20rpx;
	}
</style>
